package com.yang.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yang.dto.req.OrderSaveReqDTO;
import com.yang.dto.req.OrdersPageQueryReqDTO;
import com.yang.dto.resp.OrdersPageQueryRespDTO;
import com.yang.result.Result;
import com.yang.service.OrdersService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 订单管理控制层
 * 作者：孤城暖阳y
 * 开发时间：2025-02-26
 */
@RestController
@RequiredArgsConstructor
@Tag(name = "订单管理")
public class OrderController {

    private final OrdersService ordersService;

    @Operation(summary = "分页查询订单")
    @GetMapping("/Treasure-Pavilion-admin/order/page")
    public Result<IPage<OrdersPageQueryRespDTO>> findAll(OrdersPageQueryReqDTO requestParam) {
        System.out.println(requestParam);
        IPage<OrdersPageQueryRespDTO> ordersPageQueryRespDTOIPage = ordersService.pageQueryOrders(requestParam);
        return Result.success(ordersPageQueryRespDTOIPage);
    }

    @Operation(summary = "查询总订单数")
    @GetMapping("/Treasure-Pavilion-admin/order/count")
    public Result<Long> count() {
        return Result.success(ordersService.getOrderCount());
    }

    @Operation(summary = "查询今日订单数")
    @GetMapping("/Treasure-Pavilion-admin/order/countToday")
    public Result<Long> countToday() {
        return Result.success(ordersService.getOrderCountToday());
    }




    @Operation(summary = "更新订单信息")
    @PostMapping("/Treasure-Pavilion-admin/order/update")
    public Result<Boolean> saveOrders(@Valid OrderSaveReqDTO requestParam) {
        ordersService.saveOrders(requestParam);
        return Result.success();
    }

}
